#-*- coding: utf8 -*-
from tutor.scripts import *
from tutor.plugins.maple import *

# variáveis úteis
half = M('1/2')
t = M.t
_i, _j, _k = M('_i, _j, _k')
diff = M.diff
rr = M('`..`')
coeff = M.coeff

# parâmetros iniciais
a = oneof(1, M.sqrt(2), 2, M.sqrt(3), M.sqrt(6), 3)
A = oneof(1, 1, -1) * oneof(1, 1, 2, 3, 4)
B = oneof(1, 1, -1) * oneof(1, 1, 2, 3, 4)
C = oneof(1, 1, -1) * oneof(1, 1, 2, 3, 4)
planoEq = A * x + B * y + C * z + 1
print('plano:', planoEq)

a2 = a * a
aDouble = 2 * a
f = M.solve(planoEq, z)
fx = diff(f, x)
fy = diff(f, y)
JS = M.sqrt(fx ** 2 + fy ** 2 + 1)

# integral de superfície
area = JS * M.Pi * a2
print('area:', area)
print('circulo:', a2 * M.Pi)

jacob = JS * 2 * M.Pi * a
print('jacob:', jacob)

quadrado = JS * 4 * a2
print('quadrado:', quadrado)

soma = M.simplify((1 + fx + fy) * M.Pi * a2)
print('soma:', soma)

# cálculo do fluxo de campo
r = oneof(1, 1, -1) * oneof(1, 2, 3, 4)
s = oneof(1, 1, -1) * oneof(1, 2, 3, 4)
t = oneof(1, 1, -1) * oneof(1, 2, 3, 4)
vars = [ x, y, z ] * 3
shuffle(vars)

r = M.r
t = M.t
F = fieldF = sum(v * c * e for v, c, e in zip(vars, [r, s, t], [_i, _j, _k]))
Fx, Fy, Fz = coeff(F, _i), coeff(F, _j), coeff(F, _k)
print('campo:', fieldF)

aux = subs(z == f, -fx * Fx - fy * Fy + Fz)
aux = M.subs(x == r * cos(t), y == r * sin(t), aux)
aux = M.simplify(M.int(aux * r, r == rr(0, a)))
Phi = M.simplify(M.int(aux, t=rr(0, 2 * Pi)))
print('fluxo:', Phi)

aux = subs(z == f, -fx * Fx - fy * Fy + Fz)
aux = M.subs(x == r * cos(t), y == r * sin(t), aux)
aux = M.simplify(M.int(aux, r == rr(0, a)))
PhiJacob = M.simplify(M.int(aux, t=rr(0, 2 * Pi)))
print('fluxo:', PhiJacob)

aux = subs(z == f, (1 + fx + fy) * (Fx + Fy + Fz))
aux = M.subs(x == r * cos(t), y == r * sin(t), aux)
aux = M.simplify(M.int(aux * r, r == rr(0, a)))
PhiProd = M.simplify(M.int(aux, t=rr(0, 2 * Pi)))
print('Phi_Prod:', PhiProd)

aux = subs(z == f, M.sqrt(1 + fx ** 2 + fy ** 2) * Fz)
aux = M.subs(x == r * cos(t), y == r * sin(t), aux)
aux = M.simplify(M.int(aux * r, r == rr(0, a)))
PhiMod = M.simplify(M.int(aux, t=rr(0, 2 * Pi)))
print('PhiMod:', PhiMod)

aux = subs(z == f, M.sqrt(1 + fx ** 2 + fy ** 2) * Fz)
aux = M.int(aux, x == rr(-a, a))
aux = M.int(aux, y == rr(-a, a))
PhiQuad = M.simplify(aux)
print('PhiQuad:', PhiQuad)

